<?
session_start();

include("dbConn.php");

date_default_timezone_set("Australia/NSW");

//$link = mysql_connect('localhost', 'ravex_xos', 'aka47');
//$dbopen = mysql_select_db('ravex_xos', $link);

$userID = $_SESSION['user_id'];
$userName = mysql_result(mysql_query("SELECT name FROM users WHERE id = '$userID'"),0,0);

if (isset($userID))
{

$nameQuery = mysql_query("SELECT firstname, lastname FROM users WHERE id = '$userID'");

$firstName = mysql_result($nameQuery,0,0);
$lastName = mysql_result($nameQuery,0,1);

$abbr = @mysql_result(mysql_query("SELECT status FROM users WHERE id = '$userID'"),0,0);
$status = @mysql_result(mysql_query("SELECT status FROM status_lookup WHERE abbr = '$abbr'"),0,0);

$chosenUI = mysql_result(mysql_query("SELECT UI FROM users WHERE ID = '$userID'"),0,0);
$desUI = mysql_result(mysql_query("SELECT uiName FROM userInterfaces WHERE ID = '$chosenUI'"),0,0);

$lastLogin = date("j M Y H:i:s", strtotime(mysql_result(mysql_query("SELECT lastLogin FROM users WHERE ID = '$userID'"),0,0)));

$lastIP = mysql_result(mysql_query("SELECT lastIP FROM users WHERE ID = '$userID'"),0,0);
?>
<script src="Scripts/jQuery.js" type="text/javascript"></script>
<script src="Scripts/uiCore.js" type="text/javascript"></script>
<script type="text/javascript">
function changeUsername()
{
    var btn = document.getElementById("showUserName");
    if(btn.value == "Change")
    {
	    if(document.getElementById("newUserName").getAttribute("shown") == "true")
	    {
		    hideElement("newUserName");
	    }
	    else
	    {
		    showElement("newUserName");
		    btn.value = "Confirm";
		    showElement("cancelUserChange");
	    }
	}
	else if (btn.value == "Confirm")
	{
	
	}
}

function cancelUsername()
{
    var btn = document.getElementById("showUserName");
    btn.value = "Change";
    hideElement("cancelUserChange");
	hideElement("newUserName");
    //hideElement("");
}

function showElement(element, isClass)
{
    var desElement;
    if (isClass)
    {
        desElement = "." + element;
    }
    else
    {
        desElement = "#" + element;
	    document.getElementById(element.toString()).setAttribute("shown","true");
	}
	$(desElement).animate({width:"100px", opacity:"1.0"}, 750, "swing");	
}
function hideElement(element, isClass)
{
    var desElement;
    if (isClass)
    {
        desElement = "." + element;
    }
    else
    {
        desElement = "#" + element;
	    document.getElementById(element.toString()).setAttribute("shown","false");
	}
	$(desElement).animate({width:"0px", opacity:"0.0"}, 750, "swing");	
}
</script>

<table class="infoTable" width="100%" border="0" cellspacing="2" cellpadding="2">
  <colgroup>
  <col align="right" span="1" style="font-weight: bold; text-align: right;" />
  </colgroup>
  <tr>
    <td colspan="2" align="center"><? echo "$firstName $lastName" ?> </td>
  </tr>
  <tr>
    <td colspan="2" align="center"><hr />
    </td>
  </tr>
  <tr>
    <td class="tdHeader"> Username: </td>
    <td><table cellpadding="1" border="0" cellspacing="1">
        <tr>
          <td><span id="UserName"><? echo $userName; ?></span> </td>
          <!--<td>
                        <input type="text" id="newUserName" size="1" class="Hide" value="<? echo $userName; ?>" />
                    </td>
                    <td>
                        <input type="button" id="showUserName" onclick="changeUsername();" value="Change" />
                    </td>
                    <td>
                        <input type="button" id="cancelUserChange" onclick="cancelUsername();" class="Hide" style="width:auto;" value="Cancel" />
                    </td> -->
        </tr>
      </table></td>
  </tr>
  <tr>
    <td class="tdHeader">Status: </td>
    <td><? echo $status; ?> </td>
  </tr>
  <tr>
    <td class="tdHeader">User Interface:</td>
    <td><? echo $desUI; ?></td>
  </tr>
  <tr>
    <td class="tdHeader">Last Login:</td>
    <td><? echo $lastLogin; ?></td>
  </tr>
  <tr>
    <td class="tdHeader">Last Login IP:</td>
    <td><a href="http://geotool.servehttp.com/?ip=<? echo $lastIP; ?>" target="_blank"><? echo $lastIP; ?></a></td>
  </tr>
</table>
<?
	if ($_REQUEST['enterOS'] == "true")
	{ ?>
<div align="right">
  <input type="button" onclick="enterOS();" class="buttonfield" value="Enter OS">
</div>
<?	}
?>
<script type="text/javascript">
{
	hideElement("Hide",true);
}
</script>
<?
}
else
{
	echo 'No User Session Found';
}
mysql_close($link);
?>